package com.d0320;

import java.io.*;

public class CreateFile {
    public static void main(String[] args){
        FileInputStream fis = null;
        FileOutputStream fos = null;
        File file = new File("D:/HelloWorld.txt");
        try {
            file.createNewFile();
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (!file.exists()) {
            System.out.println(file.getName()+"  为目录！ " );
        }else {
            System.out.println(file.getName()+"  为文件！ ");
        }
        File myFile = new File("D:/IOTest");
        myFile.mkdirs();
        try {
            fis = new FileInputStream(new File("D:/HelloWorld.txt"));
            fos = new FileOutputStream(new File("D:/IOTest/HelloWorld.txt"));
            byte[] buffer = new byte[1024];
            int c = 0;
            while ((c = fis.read(buffer, 0 ,buffer.length)) !=-1){
                fos.write(buffer,0,c);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            if (null != fis){
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }if (null !=fos){
                try {
                    fis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        CreateFile createFile = new CreateFile();
        createFile.deleteFile("D:/","HelloWorld.txt");
    }
    void deleteFile (String path,String fileName){
        File file1 = new File("D:/HelloWorld.txt");
        if (file1.delete()){
            System.out.println("文件已删除！");
        }
    }
}